home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1 / Ian and Stuart's One (Australia).iso / Australasian Legends / Commercial / Rainbow Hill / MacDOS™ 2.0.0 / batches / bu.bat < prev    next >
DOS Batch File  |  1994-07-04  |  2KB  |  82 lines

  1. @echo off
  2. !  bu.bat    Batch file to backup a file or the contents of a folder
  3. !
  4. !  bu name [dest]
  5. !
  6. !  where 'name' is the item to be copied and 'dest' is the destination
  7. !  folder. Both parameters can be preceded by paths and volume IDs
  8. !  If 'dest' is missing, '2:' is assumed. Note that if the source is a folder,
  9. !  the folder itself is not copied. Therefore, bu fold1 fold2 will
  10. !  back up the contents of fold1 to fold2 rather than to fold2\fold1.
  11. !
  12. !  WARNING: the depth which can backed up is limited by the length of the
  13. !  command line and the length of your folder names.
  14. !
  15. !  To backup a folder to a folder with the same name on a floppy type:
  16. !    bu  folderPath\folderName  2:\folderName
  17. !
  18. !  To backup the contents of a folder to the current directory of volume 2 type:
  19. !    bu  folderPath\folderName
  20. !
  21. !  bu.bat calls extractName and bu1
  22. !
  23. !  Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
  24. !
  25.  
  26.     ! ensure that the first parameter is there and that the third one is not
  27.     set doserr=13
  28.     if not "%3 " == " " goto DONE_LBL
  29.     if "%1 " == " " goto DONE_LBL
  30.  
  31.     ! save the current directory: we will have to attach back in a couple of places
  32.     set bu_back=%where%
  33.  
  34.     ! determine the destination
  35.     set bu_dest=2:
  36.     if "%2 " == " " goto DEST_OK_LBL
  37.     set doserr=27
  38.     if not existdir "%2" goto DONE_LBL
  39.     !
  40.     ! Determine the full destination path by attaching to the destination
  41.     ! and looking at the global variable WHERE. This will also resolve any
  42.     ! alias in the path. Then attach back to where we were.
  43.     !
  44.     ! You cannot simply set bu_dest to %2, because it might be a relative
  45.     ! path and become useless once you move to subdirectories.
  46.     !
  47.     cd %2
  48.     set bu_dest=%where%
  49.     cd %bu_back%
  50. :DEST_OK_LBL
  51.  
  52.     onerror DONE_LBL
  53.  
  54.     ! ensure that the item to be backed up is there
  55.     if existdir "%1" goto FOLDER_LBL
  56.     !
  57.     ! it is no directory: it should be a single file
  58.     copy/u "%1" %bu_dest%
  59.     goto DONE_LBL
  60.  
  61. :FOLDER_LBL
  62.     !
  63.     ! Copy the subdirectory structure without copying any file.
  64.     ! You can achieve this by copying everything while specifying a file type
  65.     ! and/or creator which do not exist.
  66.     !
  67.     xcopy/E/C=mDOS/T=none "%1" "%bu_dest%"
  68.  
  69.     ! recursively copy the files contained in the subdirectories
  70.     set doserr=0
  71.     call bu1 "%1" "%bu_dest%"
  72.  
  73.     ! attach back to the original current directory, which was changed by bu1
  74.     cd "%bu_back%"
  75.  
  76. :DONE_LBL
  77.     if not %doserr% == 0 show %doserr%
  78.     !
  79.     ! remove the global variables
  80.     set bu_dest=
  81.     set bu_back=
  82.